import http from '@/api';
import { ADMIN_MODULE } from '@/api/helper/prefix';
import type { 
  MonitorFileRecordQuery, 
  MonitorFileRecordInfo, 
  MonitorFileRecordForm, 
  FileProcessForm,
  FileStatistics 
} from '@/api/types/datainfo/statisticsData';
import type { IPage } from '@/api/types';

/**
 * 获取监控文件记录列表
 * @param params
 * @returns {*}
 */
export const getMonitorFileRecordList = (params: MonitorFileRecordQuery) => {
  return http.get<IPage<MonitorFileRecordInfo>>(ADMIN_MODULE + `/monitor-file-record/page`, params);
};

/**
 * 获取监控文件记录详情
 * @param params
 * @returns {*}
 */
export const getMonitorFileRecordDetail = (params: { id: string }) => {
  const { id } = params;
  return http.get<MonitorFileRecordInfo>(ADMIN_MODULE + `/monitor-file-record/${id}`);
};

/**
 * 添加监控文件记录
 * @param params
 * @returns {*}
 */
export const addMonitorFileRecord = (params: MonitorFileRecordForm) => {
  return http.post(ADMIN_MODULE + `/monitor-file-record`, params);
};

/**
 * 修改监控文件记录
 * @param params
 * @returns {*}
 */
export const editMonitorFileRecord = (params: MonitorFileRecordForm) => {
  return http.put(ADMIN_MODULE + `/monitor-file-record`, params);
};

/**
 * 修改监控文件记录
 * @param params
 * @returns {*}
 */
export const edit2MonitorFileRecord = (params: MonitorFileRecordForm) => {
  return http.put(ADMIN_MODULE + `/monitor-file-record/edit`, params);
};

/**
 * 删除监控文件记录
 * @param params
 * @returns {*}
 */
export const deleteMonitorFileRecord = (params: { ids: number[] }) => {
  return http.delete(ADMIN_MODULE + `/monitor-file-record`, params);
};

/**
 * 处理文件记录
 * @param params
 * @returns {*}
 */
export const processFileRecord = (params: FileProcessForm) => {
  return http.post(ADMIN_MODULE + `/monitor-file-record/process`, params);
};

/**
 * 批量处理文件记录
 * @param params
 * @returns {*}
 */
export const batchProcessFileRecord = (params: { ids: number[]; action: string; remark?: string }) => {
  return http.post(ADMIN_MODULE + `/monitor-file-record/batch-process`, params);
};

/**
 * 获取文件统计信息
 * @param params
 * @returns {*}
 */
export const getFileStatistics = (params?: { startDate?: string; endDate?: string }) => {
  return http.get<FileStatistics>(ADMIN_MODULE + `/monitor-file-record/statistics`, params);
};

/**
 * 下载文件
 * @param params
 * @returns {*}
 */
export const downloadFile = (params: { id: number }) => {
  const { id } = params;
  return http.get(ADMIN_MODULE + `/monitor-file-record/download/${id}`, {}, { responseType: 'blob' });
};

/**
 * 重新处理失败的文件
 * @param params
 * @returns {*}
 */
export const reprocessFailedFile = (params: { id: number }) => {
  const { id } = params;
  return http.post(ADMIN_MODULE + `/monitor-file-record/reprocess/${id}`, {});
};